from django.db import models
from django.db.models.query import QuerySet

class SubclassingQuerySet(QuerySet): 
	"""
	Query set that returns subclassed instances per default, since Django doesn't.  See Django snippet #1034.  
	"""
	def __getitem__(self, k):
		result = super(SubclassingQuerySet, self).__getitem__(k) 
		if isinstance(result, models.Model): 
			return result.as_leaf_class() 
		else: 
			return result 
	def __iter__(self): 
		for item in super(SubclassingQuerySet, self).__iter__(): 
			yield item.as_leaf_class()
